// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   dealwith_ok.java

package qcs.stock;

import include.nseer_cookie.counter;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class dealwith_ok extends HttpServlet
{

	public dealwith_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			ServletContext context = session.getServletContext();
			String path = context.getRealPath("/");
			counter count = new counter(dbApplication);
			nseer_db_backup1 qcs_db = new nseer_db_backup1(dbApplication);
			if (qcs_db.conn((String)dbSession.getAttribute("unit_db_name")))
				try
				{
					String qcs_id = request.getParameter("qcs_id");
					String product_id = request.getParameter("product_id");
					String product_name = request.getParameter("product_name");
					String qualified = request.getParameter("qualified");
					String unqualified = request.getParameter("unqualified");
					String stock_id = request.getParameter("stock_id");
					String stock_name = request.getParameter("stock_name");
					String sql = (new StringBuilder("update qcs_stock set dealwith_tag='1' where qcs_id='")).append(qcs_id).append("'").toString();
					qcs_db.executeUpdate(sql);
					sql = (new StringBuilder("update stock_balance_details set qualified_amount='")).append(qualified).append("',unqualified_amount='").append(unqualified).append("',qcs_apply_tag='0' where product_id='").append(product_id).append("' and stock_id='").append(stock_id).append("'").toString();
					qcs_db.executeUpdate(sql);
					sql = (new StringBuilder("select qualified_amount,unqualified_amount from stock_balance_details where product_id='")).append(product_id).append("' and qcs_apply_tag='0'").toString();
					ResultSet rs = qcs_db.executeQuery(sql);
					double qualified_amount = 0.0D;
					double unqualified_amount;
					for (unqualified_amount = 0.0D; rs.next(); unqualified_amount += rs.getDouble("unqualified_amount"))
						qualified_amount += rs.getDouble("qualified_amount");

					sql = (new StringBuilder("update stock_balance set qualified_amount='")).append(qualified_amount).append("',unqualified_amount='").append(unqualified_amount).append("' where product_id='").append(product_id).append("'").toString();
					qcs_db.executeUpdate(sql);
					sql = (new StringBuilder("select id from stock_balance_details where product_id='")).append(product_id).append("' and qcs_apply_tag='1'").toString();
					rs = qcs_db.executeQuery(sql);
					if (!rs.next())
					{
						sql = (new StringBuilder("update stock_balance set  qcs_apply_tag='0' where product_id='")).append(product_id).append("'").toString();
						qcs_db.executeUpdate(sql);
					}
					response.sendRedirect("qcs/stock/dealwith_ok.jsp?finished_tag=0");
					qcs_db.commit();
					qcs_db.close();
				}
				catch (Exception ex)
				{
					response.sendRedirect("qcs/stock/dealwith_ok.jsp?finished_tag=3");
				}
			else
				response.sendRedirect("error_conn.htm");
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
